import { app, BrowserWindow } from "electron"
import path from "path"

const createWindow = () => {
    const win = new BrowserWindow({
        width: 600,
        height: 800,
        webPreferences: {
            contextIsolation: false,
            nodeIntegration: true,
            preload: path.join(__dirname, "../electron/preload.js")
        }
    });

    if (process.env.VITE_DEV_SERVER_URL) {
        win.loadURL(process.env.VITE_DEV_SERVER_URL)
    } else {
        // Load your file
        win.loadFile('dist/index.html');
    }

    // if (app.isPackaged) {
    //     win.loadFile(path.join(__dirname, "../index.html"))
    // } else {
    //     let url = "http://localhost:3000";
    //     win.loadFile(url);
    // }
}

app.whenReady().then(() => {
    createWindow();
    app.on("activate", () => {
        if (BrowserWindow.getAllWindows().length == 0) createWindow();
    });
});

app.on("window-all-closed", () => {
    if (process.platform != "darwin") {
        app.quit();
    }
})